package com.situ.mall.web.controller;

import com.situ.mall.common.entity.Member;
import com.situ.mall.common.exception.NoLoginException;
import com.situ.mall.common.service.IMemberService;
import com.situ.mall.common.service.IOrderInfoService;
import com.situ.mall.common.util.RequestUtil;

import com.situ.mall.common.vo.ResultVO;
import com.situ.mall.common.vo.TableVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@Controller
@RequestMapping("/personal")
public class PersonalController {

    @Autowired
    private IOrderInfoService orderInfoService;
    @Autowired
    private IMemberService memberService;

    @GetMapping("/orderList")
    @ResponseBody
    public TableVO list(Integer limit, Integer page, String status){
        Object o = RequestUtil.getCurrent();//得到当前登录的用户
        Member m = (Member)o;
        if(o == null) {//没登陆
            throw new NoLoginException();
        }else{
            return  orderInfoService.list(limit,page,status,m.getId());
        }
    }
    @GetMapping("/deleteOrder/{id}")
    @ResponseBody
    public void delete(@PathVariable Integer id){
        orderInfoService.myDelete(id);
    }


    @PostMapping("/saveInformation")
    public String save(Member m){

        memberService.updateInformation(m.getUsername(),m.getTel(),m.getSex(),m.getEmail());
        return "redirect:/logout";
    }

    //个人中心修改密码
    @PostMapping("/resetPassword")
    public String reset(String oldpassword, String newpassword1, String newpassword2){

          memberService.updatePassword(oldpassword,newpassword1,newpassword2);
        return "redirect:/logout";
    }

    @GetMapping("/confirm")
    public String confirm( Integer id){

        orderInfoService.confirm(id);
    return "order";
    }

}
